﻿Public Class frmNhaXuatBan

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        PhucHoiNutSua()
        clsNhaXuatBan.Them(txtMaNXB.Text, txtTenNXB.Text, txtDiaChi.Text, txtDienThoai.Text)
        DatNXB.DataSource = clsNhaXuatBan.DSNhaXuatBan
        btnLamMoi_Click(sender, e)
    End Sub

    Private Sub frmNhaXuatBan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DatNXB.DataSource = clsNhaXuatBan.DSNhaXuatBan
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        PhucHoiNutSua()
        If MsgBox("Bạn có muốn xóa nhà xuất bản  có mã =" & txtMaNXB.Text & " không ?", MsgBoxStyle.YesNo, "Thông báo") = MsgBoxResult.Yes Then

            If Not clsNhaXuatBan.Xoa(txtMaNXB.Text.Trim) Then
                MsgBox("Không thể xóa nhà xuất bản có mã " & txtMaNXB.Text & ".Có thể sách của nhà xuất bản này vẫn còn tồn tại!", MsgBoxStyle.Critical, "Loi")
            End If

            DatNXB.DataSource = clsNhaXuatBan.DSNhaXuatBan

            'clsNhaXuatBan.Xoa(txtMaNXB.Text)
            'DatNXB.DataSource = clsNhaXuatBan.DSNhaXuatBan
        End If


    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Hide()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click

        If btnSua.Text = "Sửa" Then
            txtMaNXB.Text = DatNXB.CurrentRow.Cells("MaNXB").Value
            txtTenNXB.Text = DatNXB.CurrentRow.Cells("TenNXB").Value
            txtDiaChi.Text = DatNXB.CurrentRow.Cells("DiaChi").Value
            txtDienThoai.Text = DatNXB.CurrentRow.Cells("DienThoai").Value
            btnSua.Text = "Lưu lại"
        Else

            btnSua.Text = "Sửa"
            clsNhaXuatBan.Sua(txtMaNXB.Text, txtTenNXB.Text, txtDiaChi.Text, txtDienThoai.Text)
            DatNXB.DataSource = clsNhaXuatBan.DSNhaXuatBan
            btnLamMoi_Click(sender, e)



        End If
    End Sub


    Private Sub DatNXB_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DatNXB.CellDoubleClick
        PhucHoiNutSua()
        btnSua_Click(sender, e)
    End Sub
    Private Sub PhucHoiNutSua()

        btnSua.Text = "Sửa"
    End Sub

    Private Sub btnLamMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamMoi.Click

        PhucHoiNutSua()
        txtMaNXB.Text = ""
        txtTenNXB.Text = ""
        txtDiaChi.Text = ""
        txtDienThoai.Text = ""

    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        PhucHoiNutSua()
        DatNXB.DataSource = clsNhaXuatBan.TimKiem(txtTuKhoa.Text)

    End Sub

    Private Sub btnReLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReLoad.Click
        DatNXB.DataSource = clsNhaXuatBan.DSNhaXuatBan
        txtTuKhoa.Text = ""

    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub
End Class